package com.hrms.web.sys_menu.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hrms.web.sys_menu.entity.AssignTreeParm;
import com.hrms.web.sys_menu.entity.AssignTreeVo;
import com.hrms.web.sys_menu.entity.MakeMenuTree;
import com.hrms.web.sys_menu.entity.SysMenu;
import com.hrms.web.sys_menu.mapper.SysMenuMapper;
import com.hrms.web.sys_menu.service.SysMenuService;
import com.hrms.web.sys_user.entity.SysUser;
import com.hrms.web.sys_user.service.SysUserService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Title: SysMenuServiceImpl
 * @Author zhanji
 * @Package com.hrms.web.sys_menu.service.Impl
 * @description:
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    @Override
    public List<SysMenu> getParent() {
        String[] type ={"0","1"};
        List<String> strings = Arrays.asList(type);
        QueryWrapper<SysMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(SysMenu::getType, strings).orderByDesc(SysMenu::getOrderNum);
        List<SysMenu> menuList = this.baseMapper.selectList(queryWrapper);
        //组装顶级树
        SysMenu menu = new SysMenu();
        menu.setTitle("顶级菜单");
        menu.setLabel("顶级菜单");
        menu.setParentId(-1L);
        menu.setMenuId(0L);
        menu.setValue(0L);
        menuList.add(menu);
        //组装菜单树
        List<SysMenu> tree = MakeMenuTree.makeTree(menuList, -1L);
        return tree;
    }

    @Override
    public List<SysMenu> selectMenuByUserId(Long userId) {
        return this.baseMapper.selectMenuByUserId(userId);
    }

    @Override
    public List<SysMenu> selectMenuByRoleId(Long roleId) {
        return this.baseMapper.selectMenuByRoleId(roleId);
    }

}
